//
//  HttpManagerCenter+Login.m
//  HiMaster3
//
//  Created by jinghao on 16/4/12.
//  Copyright © 2016年 jinghao. All rights reserved.
//

#import "HttpManagerCenter+Login.h"

@implementation HttpManagerCenter (Login)
//用户登录注册
- (RACSignal*)loginByPhone:(NSString*)phone code:(NSString*)code resultClass:(Class)resultClass{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_DeviceToken_Key] forKey:@"deviceToken"];
    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_GetuiToken_Key] forKey:@"clientId"];
    [params setObjectNotNull:phone forKey:@"mobile"];
    [params setObjectNotNull:code forKey:@"code"];
    return [self doRacPost:@"c=iuser&a=loginOrRegister" parameters:params resultClass:resultClass];
}
//发送验证码
- (RACSignal*)sendPhoneCode:(NSString*)phone resultClass:(Class)resultClass{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:phone forKey:@"mobile"];
    return [self doRacPost:@"c=iuser&a=verify_sms" parameters:params resultClass:resultClass];
}

//自动登录接口
- (RACSignal*)autologinByPhone:(NSString*)phone SecurityCode:(NSString*)code  resultClass:(Class)resultClass{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_DeviceToken_Key] forKey:@"deviceToken"];
    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_GetuiToken_Key] forKey:@"clientId"];
    [params setObjectNotNull:phone forKey:@"mobile"];
    [params setObjectNotNull:code forKey:@"security_code"];
//    [params setObjectNotNull:[password md5HexDigest] forKey:@"password"];
    return [self doRacPost:@"c=iuser&a=by_security_code_login" parameters:params resultClass:resultClass];
}

//手机号修改接口
- (RACSignal*)changePhone:(NSString*)newPhone SecurityCode:(NSString*)code  resultClass:(Class)resultClass{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:newPhone forKey:@"mobile"];
    [params setObjectNotNull:code forKey:@"code"];
    return [self doRacPost:@"c=iuser&a=change_mobile" parameters:params resultClass:resultClass];
}


//第三方登录接口
- (RACSignal*)otherLoginByPlatform:(NSString*)platform uid:(NSString*)uid unionId:(NSString*)unionId  nickname:(NSString*)nickname iconUrl:(NSString*)iconUrl gender:(NSString*)gender resultClass:(Class)resultClass{
    
    if ([platform isEqualToString:@"wxsession"]) {
        platform=@"wechat";
    }
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_DeviceToken_Key] forKey:@"deviceToken"];
    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_GetuiToken_Key] forKey:@"clientId"];
    [params setObjectNotNull:platform forKey:@"login_type"];
    if([platform isEqual:@"wechat"]){
        [params setObjectNotNull:unionId forKey:@"third_party_id"];
        [params setObjectNotNull:uid forKey:@"weixin_id"];
    }else{
        [params setObjectNotNull:uid forKey:@"third_party_id"];
    }
//    [params setObjectNotNull:uid forKey:@"weixin_id"];
    [params setObjectNotNull:nickname forKey:@"nikename"];
    [params setObjectNotNull:iconUrl forKey:@"img_top"];
    [params setObjectNotNull:gender forKey:@"sex"];

    return [self doRacPost:@"c=iuser&a=login_third_party" parameters:params resultClass:resultClass];
}

//退出登录
- (RACSignal*)logoutWithUid:(NSString *)uid resultClass:(Class)resultClass
{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:uid forKey:@"uid"];
//    [params setObjectNotNull:[NSUserDefaults arcObjectForKey:APP_GetuiToken_Key] forKey:@"clientId"];
    return [self doRacPost:@"c=iuser&a=logout" parameters:params resultClass:resultClass];
}


//重置密码    未找到
- (RACSignal*)resetPassword:(NSString*)password password_new:(NSString*)password_new resultClass:(Class)resultClass
{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:[password md5HexDigest] forKey:@"password"];
    [params setObjectNotNull:[password_new md5HexDigest] forKey:@"password_new"];
    return [self doRacPost:@"c=iuser&a=reset_pwd" parameters:params resultClass:resultClass];
}

//绑定手机
- (RACSignal*)bindMobile:(NSString*)mobile code:(NSString*)code resultClass:(Class)resultClass{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:mobile forKey:@"mobile"];
    [params setObjectNotNull:code forKey:@"code"];
    return [self doRacPost:@"c=iuser&a=bind_mobile" parameters:params resultClass:resultClass];

}

//实名认证
- (RACSignal*)certificationWithname:(NSString*)name identityId:(NSString*)identityId positive_photo:(NSString * )positive_photo opposite_photo:(NSString *)opposite_photo resultClass:(Class)resultClass
{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObjectNotNull:name forKey:@"name"];
    [params setObjectNotNull:identityId forKey:@"identityId"];
    [params setObjectNotNull:positive_photo forKey:@"positive_photo"];
    [params setObjectNotNull:opposite_photo forKey:@"opposite_photo"];
    return [self doRacPost:@"c=iuser&a=certification" parameters:params resultClass:resultClass];
}
@end
